package cn.edu.hitwh.yibao.controller;
import cn.edu.hitwh.yibao.form.FacilityForm;
import cn.edu.hitwh.yibao.service.FacilityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

@Controller
public class FacilityController {
	@Autowired
	private FacilityService facilityService;
	
	@GetMapping("/facility")
	public String facility() {
		return "/facility/select";
	}
	
	@PostMapping("/facility")
	public String facilityResult(FacilityForm facilityForm, Model model) {
		return facilityService.select(facilityForm, model);
	}
	
	@GetMapping("/facility/addInit")
	public String addInit(){
		return "/facility/add";
	}
	
	@PostMapping("/facility/add")
	public String add(FacilityForm facilityForm, Model model) {
		return facilityService.add(facilityForm, model);
	}
	
	@GetMapping("/facility/addComplete")
	public String addComplete(Model model) {
		model.addAttribute("addResult", "添加新设施信息成功！");
		return "/facility/select";
	}
	
	@GetMapping("/facility/updateInit")
	public String updateInit(String serId, Model model) {
		return facilityService.updateInit(serId,  model);
	}
	
	@PostMapping("/facility/update")
	public String update(FacilityForm facilityForm, Model model) {
		return facilityService.update(facilityForm, model);
	}
	
	@GetMapping("/facility/updateComplete")
	public String updateComplete() {
		return "/facility/select";
	}
	
	@GetMapping("/facility/delete")
	public String delete(String serId, Model model) {
		return facilityService.delete(serId,  model);
	}
	
	@GetMapping("/facility/deleteComplete")
	public String deleteComplete(Model model) {
		model.addAttribute("deleteResult", "删除设施信息成功！");
		return "/facility/select";
	}
	
	@GetMapping("/facility/detail")
	public String detail(String serId, Model model) {
		return facilityService.detail(serId,  model);
	}
	
}
